package com.sf.fy.uav.applet.scenicspot;

import com.sf.fy.uav.common.request.operate.CommodityReq;
import com.sf.fy.uav.common.response.operational.CommodityRes;
import com.sf.fy.uav.common.utils.RespJsonPageData;
import com.sf.fy.uav.common.utils.Rs;
import com.sf.fy.uav.controller.BusinessRest;
import com.sf.fy.uav.controller.CommodityRest;
import com.sf.fy.uav.entity.Business;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ta136817
 */
@RestController
@RequestMapping("/home/commodity/")
@RequiredArgsConstructor
@Tag(name = "商品管理", description = "商品管理")
@Api(tags = "商品管理")
public class CommodityController {

    private final BusinessRest businessRest;

    private final CommodityRest commodityRest;
    @GetMapping("get-commodity")
    public RespJsonPageData<CommodityRes> getScenicSpot(@RequestParam Integer page, @RequestParam Integer size, @RequestParam(required = false) String name, @RequestParam(required = false) Integer status, @RequestParam(required = false) String businessId) {
        CommodityReq commodityReq = new CommodityReq();
        commodityReq.setPage(page);
        commodityReq.setSize(size);
        commodityReq.setName(name);
        commodityReq.setBusinessId(businessId);
        commodityReq.setStatus(status);
        return commodityRest.getPageCommodity(commodityReq);
    }

    @GetMapping("get-businessName")
    @Operation(tags = "查询商家下拉列表", description = "查询商家下拉列表")
    @CrossOrigin
    public  Rs<List<Business>>  getBusinessName(@RequestParam(required = false) String id, @RequestParam(required = false) String name) {
        return businessRest.queryBusinessName(id,name);
    }
    @PostMapping ("add-commodity")
    public Rs<Integer> addCommodity(@RequestBody CommodityReq commodityReq) {
       return commodityRest.addCommodity(commodityReq);
    }
    @PostMapping ("edit-commodity")
    public Rs<Integer> editCommodity(@RequestBody CommodityReq commodityReq) {
        return commodityRest.editCommodity(commodityReq);
    }
}
